﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ImageUploaderUpgrade
{
    class Program
    {
        static void Main(string[] args)
        {

            System.Threading.Thread.Sleep(2000);
            try
            {
                string zipFile = "";//解压文件            
                foreach (var arg in args)
                {
                    Console.WriteLine(arg);
                    if (!string.IsNullOrEmpty(arg))
                    {
                        zipFile = arg;
                        if (System.IO.File.Exists(zipFile))
                        {
                            string zipPath = System.IO.Path.GetDirectoryName(zipFile);
                            Console.WriteLine(zipFile);
                            Console.WriteLine(zipPath);
                            Console.WriteLine("正在升级...");

                            Common.ZipUtility.UnZip(zipFile, zipPath, "");
                            Console.WriteLine("升级完成，正在重新启动程序！");
                            string mainProgram = zipPath + "\\ImageUploader.exe";
                            System.IO.File.Delete(zipFile);
                            //string main = System.Configuration.ConfigurationSettings.AppSettings["Main"];
                            System.Diagnostics.Process.Start(mainProgram);
                        }
                    }
                }
                Console.WriteLine("3s后自动退出");
                System.Threading.Thread.Sleep(3000);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine("升级失败");
                System.Threading.Thread.Sleep(3000);
                Console.ReadLine();
            }
        }
    }
}
